package it.heima.xmy.Demo1;

import java.util.*;

/*需求：一个年级有若干个班级，每个班级有若干个学生；要求：
1. 学生具有学号、姓名和成绩，学号和学生信息是一一对应的；
2. 使用集合保存这个年级的所有学生的信息，然后遍历输出；
思路：
- 班级：Map<Integer,Student> 键：学号，值：学生对象
- 年级：List<Map<Integer,Student>> 使用List集合将每个班级保存*/
public class ClassMapDemo07 {
    public static void main(String[] args) {
        List<Map<Integer,Student>> list = new ArrayList<>();
        Map<Integer, Student> map1 = new HashMap<>();
        Student student1 = new Student(1001, "一一", 99);
        Student student2 = new Student(1002, "一二", 98);
        Student student3 = new Student(1003, "一三", 95);
        Student student4 = new Student(1004, "一四", 96);

        Map<Integer, Student> map2 = new HashMap<>();
        Student student5 = new Student(2001, "二一", 97);
        Student student6 = new Student(2002, "二二", 94);
        Student student7 = new Student(2003, "二三", 92);
        Student student8 = new Student(2004, "二四", 93);

        Map<Integer, Student> map3 = new HashMap<>();
        Student student9 = new Student(3001, "三一", 91);
        Student student10 = new Student(3002, "三二", 90);
        Student student11 = new Student(3003, "三三", 84);
        Student student12 = new Student(3004, "三四", 86);
        map1.put(student1.getId(), student1);
        map1.put(student2.getId(), student2);
        map1.put(student3.getId(), student3);
        map1.put(student4.getId(), student4);
        map2.put(student5.getId(), student5);
        map2.put(student6.getId(), student6);
        map2.put(student7.getId(), student7);
        map2.put(student8.getId(), student8);
        map3.put(student9.getId(), student9);
        map3.put(student10.getId(), student10);
        map3.put(student11.getId(), student11);
        map3.put(student12.getId(), student12);


        list.add(map1);
        list.add(map2);
        list.add(map3);
        System.out.println(list.get(0)+"\n"+list.get(1)+"\n"+list.get(2)+"\n");


    }

    public static class Student {
        private int id;
        private String name;
        private double score;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Student student = (Student) o;
            return id == student.id;
        }

        @Override
        public int hashCode() {
            return Objects.hash(id);
        }

        public Student() {
        }

        public Student(int id, String name, double score) {
            this.id = id;
            this.name = name;
            this.score = score;
        }

        /**
         * 获取
         * @return id
         */
        public int getId() {
            return id;
        }

        /**
         * 设置
         * @param id
         */
        public void setId(int id) {
            this.id = id;
        }

        /**
         * 获取
         * @return name
         */
        public String getName() {
            return name;
        }

        /**
         * 设置
         * @param name
         */
        public void setName(String name) {
            this.name = name;
        }

        /**
         * 获取
         * @return score
         */
        public double getScore() {
            return score;
        }

        /**
         * 设置
         * @param score
         */
        public void setScore(double score) {
            this.score = score;
        }

        public String toString() {
            return "Student{id = " + id + ", name = " + name + ", score = " + score + "}";
        }
    }
}
